package com.itheima.controller.sms;

import com.itheima.core.PageInfo;
import com.itheima.core.R;
import com.itheima.pojo.sms.SmsHomeNewProduct;
import com.itheima.service.sms.SmsHomeNewProductService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("home/newProduct")
public class SmsHomeNewProductController {

    @DubboReference
    private SmsHomeNewProductService newProductService;

    /**
     * 添加首页新品
     * @param
     * @return
     */
    @PostMapping("create")
    public R create(@RequestBody List<SmsHomeNewProduct> list){
        newProductService.create(list);
        return R.success("添加成功");
    }

    /**
     * 批量删除首页新品
     * @param ids
     * @return
     */
    @PostMapping("delete")
    public R delete(@RequestParam("ids") List<Long> ids){
        newProductService.delete(ids);
        return R.success("删除改成");
    }

    /**
     * 批量修改首页新品状态
     * @param ids
     * @param recommendStatus
     * @return
     */
    @PostMapping("update/recommendStatus")
    public R updateRecommendStatus(@RequestParam("ids") List<Long> ids,@RequestParam Integer recommendStatus){
        newProductService.updateRecommendStatus(ids,recommendStatus);
        return R.success("修改状态成功");
    }

    /**
     * 修改首页新品排序
     * @param sort
     * @param id
     * @return
     */
    @PostMapping("update/sort/{id}")
    public R updateSort(@RequestParam Integer sort,@PathVariable("id") Long id){
        newProductService.updateSort(sort,id);
        return R.success("修改成功");
    }

    /**
     * 分页查询
     * @param pageNum
     * @param pageSize
     * @param productName
     * @param recommendStatus
     * @return
     */
    @GetMapping("list")
    public R list(@RequestParam(defaultValue ="1") Integer pageNum,
                             @RequestParam(defaultValue ="5") Integer pageSize,
                             @RequestParam(value = "productName",required = false)String productName,
                             @RequestParam(value = "recommendStatus",required = false)Integer recommendStatus)
    {
        PageInfo page = newProductService.getList(pageNum,pageSize,productName,recommendStatus);
        return R.success(page);

    }
}
